package com.cci.kangdao.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.mybatis.spring.annotation.MapperScan;

import com.cci.kangdao.dao.model.CompanyT;
import com.cci.kangdao.dao.model.CourseTrainingT;
import com.cci.kangdao.dao.model.SMNT;
import com.cci.kangdao.dao.model.ServiceToolT;
import com.cci.kangdao.dao.model.WorkOrderT;

/**
 * 服务技师资质表dao
 *
 */
@MapperScan
public interface EngineerQualifyTDao {
	
	/**
	 * 根据服务技师用户id获取服务技师所有资质
	 * @return
	 */
	/*@Select("select b.UserPhone,\r\n" +
			"		stuff((select ','+CAST(EngineTypeName as varchar(50)) from  EngineerQualify_T  \r\n" +
			"            where b.UserPhone=UserPhone and Flag = 0 \r\n" + 
			"            for xml path('')),1,1,'') as EngineTypeIds	\r\n" + 
			"from User_T a \r\n" + 
			"inner join EngineerQualify_T b on a.Phone = b.UserPhone\r\n" + 
			"inner join EngineType_T c on b.EngineTypeId = c.ID\r\n" + 
			"where a.ID = #{UserId} and a.Flag =0 and b.Flag =0 \r\n" + 
			"group by b.UserPhone")*/
	@Select("select stuff((select ','+CAST(EngineTypeName as varchar(50)) from  EngineerQualify_T\n" +
			"where b.UserPhone=UserPhone and Flag = 0 \n" +
			"for xml path('')),1,1,'') as EngineTypeName\n" +
			"from User_T a \n" +
			"inner join EngineerQualify_T b on a.Phone = b.UserPhone\n" +
			"inner join EngineType_T c on b.EngineTypeId = c.ID\n" +
			"where a.ID =#{UserId} and a.Flag =0 and b.Flag =0\n" +
			"group by b.UserPhone")
	public String getEngineerQualifyTByUserId(long UserId);


	@Select("select distinct EngineTypeName from EngineerQualify_T where UserPhone =#{phone} and Flag=0")
	List<String> getEngineerQualifyListByPhone(String phone);

	@Select("select SMNList from EngineerQualifyWithSMN_T where UserPhone =#{phone} and Flag=0")
	List<String> getEngineerQualifySMNListByPhone(String phone);

	 /**
	  * @description:根据服务站授权码查询资质
	  * @param:
	  * @return:
	  * @exception:
	  * @author: shiliqiang
	  * @company: CTY Technology Co.,Ltd
	  * @since: 2021/12/8 13:12
	  * @version: V1.0
	  */
	@Select("select SMNList from EngineerQualifyWithSMN_T where StationNo =#{stationNo} and Flag=0")
	List<String> getEngineerQualifySMNListByStationNo(String phone);

	void updateFlagByCondition(Map<String,Object> map);


	int deleteByPhoneAndTypeName(Map<String,Object> map);


	//DBU获取服务技师资质方法
	@Select("select * from EngineerQualify_T where PromotionId=#{promotionId} and Flag = 0")
	Map<String,Object> getEngineerQualifyTByPromotionId(@Param("promotionId")String promotionId);

	@Select("select * from EngineerQualify_T where Flag = 0 and UserPhone = #{userPhone} and EngineTypeName = #{engineTypeName}")
	Map<String, Object> selectByPhoneAndTypeName(@Param("userPhone") String userPhone, @Param("engineTypeName") String engineTypeName);

	int updateByPrimaryKeySelective(Map<String,Object> map);
}
